// pages/pages-list/my-activity/my-activity.js
import api from '../../../utils/api/api'
import tool from "../../../utils/publics/tool"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    exhibition: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getData();
  },
  // 获取数据
  getData() {
    api.my_enroll().then(res => {
      let {
        code,
        data,
        msg
      } = res;
      if (code == 1) {
        this.setData({
          exhibition: data
        })
      }
    })
  },
  // 跳转
  skip(e) {
    let id = e.detail.id;
    let pink_id = e.detail.pink_id;
    let index = e.detail.index;
    let info = this.data.exhibition[index];
    if (info.true_status == 1 ) {  // 1报名成功,2拼团成功,3拼团中,4待支付,5待审核,6拼团失败  
      tool.jump_nav(`/pages/pages-list/success/success?id=${id}`)
    }else if(info.true_status==2){
      return tool.jump_nav(`/pages/pages-list/group-details/group-details?id=${info.pink_id}`)
    } else if(info.true_status == 3){
      tool.jump_nav(`/pages/pages-list/group-details/group-details?id=${pink_id}`)
    }
  },
  // 支付
  go(e){
    let exhibition = this.data.exhibition;
    let type =e.detail.type;
    let index =e.detail.index;
    if(type==1){     // 取消支付
      api.cancel_pay({id:exhibition[index].id}).then(res=>{
        let {code,data,msg} =res;
        if(code==1){
          tool.alert("取消成功",1);
          this.getData();
        }
      })
    }else{           // 去支付
      api.order_pay({id:exhibition[index].id}).then(res=>{
        let {code,data,msg} =res;
        let this_ = this;
        if(code==1){
          wx.requestPayment({
            ...data,
            success(res) {
              // this_.getData();
              if(exhibition[index].true_status==1){
                tool.alert("报名成功",1);
                // setTimeout(() => {
                  tool.jump_rel(`/pages/pages-list/success/success?id=${exhibition[index].id}`)
                // }, 500)
              }else{
                // setTimeout(() => {
                   tool.jump_nav(`/pages/pages-list/group-details/group-details?id=${exhibition[index].pink_id}`)
                // }, 500)
              }
             
              
            },
            fail(res) {}
          })
        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})